/**
 * Created by wangshaohua on 2018/1/13.
 */
moduleBadge.controller("BadgeQuery", function (LanguageService, $scope, $log, $state, LoadingService, ConstantService, DialogService, OldBadgeResource) {
    $scope.$on("$viewContentLoaded", function () {
        pageOnLoad();
        ConstantService.addState($state.current, true, LanguageService.language('徽章管理'));
        $scope.pagination = new Pagination();
        $scope.pagination.setPageClickFn($scope.queryBadge);
        $scope.queryBadge($scope.pagination.currentPageNo);
    });

    $scope.onQueryKeyDown = function () {
        if (event.keyCode == 13) {
            $scope.queryBadge(1);
        }
    }

    $scope.queryPara = {};
    $scope.queryBadge = function (pageNo) {
        //LoadingService.show();
        OldBadgeResource.queryPage({pageNo: pageNo - 1, pageSize: 10}, $scope.queryPara, function (queryResult) {
            $log.debug("查询结果", queryResult);
            $scope.queryResult = queryResult;
            $scope.pagination.setPage(queryResult, pageNo);
            //LoadingService.hide();
        });
    };

    $scope.addBadge = function () {
        DialogService.open("addBadge");
    };

    $scope.editBadge = function (badge) {
        $scope.currentBadge = badge;
        //LoadingService.show();
        OldBadgeResource.findById({badgeId: badge.id}, function (badgeResult) {
            $log.debug("搜索结果", badgeResult);
            $scope.editingBadge = badgeResult;
            //LoadingService.hide();
            DialogService.open("editBadge", $scope);
        }, function () {
            //LoadingService.hide();
        });
    };

    $scope.refresh = function () {
        $scope.queryPara = {};
    };

});